package com.eveinfo.api.utils.skilllist;

import java.util.ArrayList;

import com.eveinfo.api.ApiResponse;

public class ApiSkills extends ApiResponse {

	private static final long serialVersionUID = -7110021186055406330L;

	private final ArrayList<ApiSkillGroup> skillGroups;

	public ApiSkills() {
		this.skillGroups = new ArrayList<ApiSkillGroup>();
	}

	public void addSkillGroup(ApiSkillGroup skillGroup) {
		this.skillGroups.add(skillGroup);
	}

	public ArrayList<ApiSkillGroup> getSkillGroups() {
		return skillGroups;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for (ApiSkillGroup group : skillGroups) {
			sb.append(group.getGroupName() + "\n");
			sb.append(group.toString() + "\n");
		}
		return sb.toString();
	}

	public String getSkillName(int skillId) {
		for (ApiSkillGroup group : skillGroups) {
			String name = group.getSkillName(skillId);
			if (name != null)
				return name;
		}
		return null;
	}

	public ApiSkill getSkill(int skillId) {
		for (ApiSkillGroup group : skillGroups) {
			ApiSkill s = group.getSkill(skillId);
			if (s != null)
				return s;
		}
		return null;
	}

	public int getGroupId(int skillId) {
		for (ApiSkillGroup next : skillGroups) {
			if (next.contains(skillId)) {
				return next.getGroupID();
			}
		}
		return -1;
	}

	public String getGroupName(int groupId) {
		for (ApiSkillGroup group : skillGroups) {
			if (groupId == group.getGroupID())
				return group.getGroupName();
		}
		return null;
	}
}
